﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using zichan.BLL;
namespace zichan.Controllers
{
    public class MachineRoomLogsController : BaseController
    {
        // GET: MachineRoomLogs
        public ActionResult Index(int? sortId, string keyWord, DateTime? sdt, DateTime? edt, int? page, int? pageSize, int? pageCount, int? selectedPage)
        {
            page = page ?? 1;
            pageSize = pageSize ?? 10;
            if (selectedPage.HasValue)
                page = selectedPage;
            if (pageCount.HasValue)
                page = page <= pageCount ? page : pageCount;
            if (page < 1) page = 1;
            ViewBag.page = page;
            ViewBag.pageSize = pageSize;
            ViewBag.selectedPage = selectedPage;
            List<SelectListItem> pitems = new List<SelectListItem> { new SelectListItem { Value = "10", Text = "10" }, new SelectListItem { Value = "20", Text = "20" }, new SelectListItem { Value = "50", Text = "50" }, new SelectListItem { Value = "100", Text = "100" } };
            ViewBag.pageSizes = new SelectList(pitems, "Value", "Text", ViewBag.pageIndex);

            ViewBag.sortId = sortId;
            List<SelectListItem> items = new List<SelectListItem> { new SelectListItem { Value = "1", Text = "机房" }, new SelectListItem { Value = "2", Text = "IP" }, new SelectListItem { Value = "3", Text = "机柜" } };
            ViewBag.sortIds = new SelectList(items, "Value", "Text", sortId);
            ViewBag.keyWord = keyWord;
            ViewBag.sdt = sdt;
            if (sdt.HasValue)
                ViewBag.sdt = sdt.Value.ToShortDateString();
            ViewBag.edt = edt;
            if (edt.HasValue)
                ViewBag.edt = edt.Value.ToShortDateString();
            return View(MachineRoomLogService.List(sortId,keyWord,sdt,edt,page.Value,pageSize.Value));
        }
    }
}